<template>
  <div>
    <navi :title="roomData.name">
      <template v-slot>
        <h1>哈哈哈</h1>
      </template>
      
    </navi>
    <div class="msgView">
      <div class="msgItem">
        <img class="headICon" src="" alt="">
        <div class="message"></div>
      </div>
    </div>
  </div>
</template>
<script setup>
import {ref,reactive,getCurrentInstance} from 'vue'
import {useRoute} from 'vue-router'
import navi from '../../components/navigatebar.vue'
const route=useRoute()
const {proxy}=getCurrentInstance()
const roomData=JSON.parse(route.query.data) 
const ws= new WebSocket('ws://127.0.0.1:8540/test')
let data=reactive([])
let msg=ref('')
ws.onopen=()=>{
    // 打开WebSocket连接后立刻发送一条消息:
    ws.send(JSON.stringify({user:'jiahui',content:'123',type:'login',to:'all'}) ); 
}
ws.onmessage=(msg)=>{
    //获取所有信息展示在客户端
    let getmsg=json.parse(msg)
    
    data.push(msg.data)
}
//客户端监控异常信息
ws.onerror=(error)=>{
    if(error){
        console.log(error)
    }
}
ws.onclose=()=>{
    console.log(`下线了`);
}
const send=()=>{
    ws.send(JSON.stringify({user:'jiahui',content:msg.value}))
}
</script>
<style lang="less" scoped>

</style>